package com.jkoss.wine.system.service.impl;

import com.jkoss.common.util.CommonUtil;
import com.jkoss.wine.system.entity.Commonly;
import com.jkoss.wine.system.entity.Permission;
import com.jkoss.wine.system.entity.RolePermission;
import com.jkoss.wine.system.mapper.CommonlyMapper;
import com.jkoss.wine.system.mapper.PermissionMapper;
import com.jkoss.wine.system.service.ICommonlyService;
import com.jkoss.wine.system.service.IPermissionService;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 常用功能 服务实现类
 * 
 * @Author 周华军
 * @Version 1.0, 2018-11-01
 * @See
 * @Since com.jkoss.wine.system.service.impl
 * @Description: TODO
 */
@Service
public class CommonlyServiceImpl extends ServiceImpl<CommonlyMapper, Commonly> implements ICommonlyService {

	@Override
	public List<String> selectPidByRid(String id) {
		return this.baseMapper.selectPidByRid(id);
	}

	@Override
	public boolean updateCommonly(String id, String[] pid) {
		// 删除所有常用功能
		Wrapper wrapper = Condition.create().eq("rid", id);
		this.baseMapper.delete(wrapper);
		if (!CommonUtil.isBlank(pid)) {
			List<Commonly> commonlies = new ArrayList();
			for (String pidStr : pid) {
				Commonly commonly = new Commonly();
				commonly.setRid(id);
				commonly.setPid(pidStr);
				commonlies.add(commonly);
			}
			return this.insertBatch(commonlies);
		} else {
			return true;
		}
	}

	@Override
	public List<Permission> selectByMeid(String eid) {
		return this.baseMapper.selectByMeid(eid);
	}
}
